/* 构造函数继承 */
function Person(name, age) {
  this.name = name;
  this.age = age;
  this.setName = function () {};
}
// 构造函数无法继承原型对象的方法/属性
Person.prototype.setAge = function () {};

function Student(name, age, price) {
  // Student通过call改变this继承Person的方法
  Person.call(this, name, age); // 相当于: this.Person(name, age)
  /*this.name = name
  this.age = age*/
  this.price = price;
}

var s1 = new Student("Tom", 20, 15000);

console.log(s1);

console.log("----------------------------------------------------");

/*
  原型继承: 实现：子类的prototype等于父类的实例(就是new一个父类赋值给子类的prototype)
*/
function Animal() {
  this.age = function () {
    console.log("age");
  };
}

Animal.prototype.say = function () {
  console.log("Animal");
};

function Dog() {}
Dog.prototype = new Animal();
// Dog.prototype = new Animal();

let d = new Dog();
d.say(); // Animal
d.age(); // age
console.log(d.age);
